﻿using System;

namespace IWMAG.Core.EnhancedProperties.PropertyNodes
{
    internal partial class PropertyNodeList<T>
    {
        private class StartNode<K> : PropertyNode<K>
            where K : T
        {
            public Action<K> PropertyChangedDelegate { get; set; }
            public StartNode(Action<K> propertyChanged,  Action listModified)
                : base(int.MaxValue)
            {
                this.PropertyChangedDelegate = propertyChanged;
                this.ListModifiedDelegate = listModified;
            }

            public override K GetNodeValue()
            {
                return Next.GetNodeValue();
            }

            public override void SuccessorChanged(K value)
            {
                var c = this.PropertyChangedDelegate;
                if (c != null)
                {
                    c(value);
                }
            }

            public override void NotifyListModified()
            {
                var c = this.ListModifiedDelegate;
                if (c != null)
                {
                    c();
                }
            }

            public override void Dispose()
            {
                base.Dispose();
                this.PropertyChangedDelegate = null;
            }

            public Action ListModifiedDelegate { get; set; }
        }
    }
}
